#两个线程检测文件夹中 新添加的文件名
import os,shutil
import time
from multiprocessing import Queue
from threading import Thread

class Putfiel(Thread) :
    def __init__(self,q):
        super().__init__()
        self.q = q
    def run(self) :
        while True:
            time.sleep(2)
            dirs = os.listdir(path)
            if len(dirs):
                for filename in dirs:
                    self.q.put(filename)
                    print('进来一个文件%s'%filename)
class Getfile(Thread) :
    def __init__(self,q):
        super().__init__()
        self.q = q
    def run(self):
        while True :
            if self.q.qsize() :
               filename =  self.q.get()
               print('取出一个文件%s' % filename)
               self.moveFile(filename)

    def moveFile(self,filename):
        shutil.move(os.path.join('./file',filename),os.path.join('./filenew',filename))



if __name__ =='__main__' :
    path = 'file'

    q = Queue()
    if not os.path.isdir(path) :
        os.mkdir(path)
    t1 =Putfiel(q)
    t2 = Getfile(q)
    t1.start()
    t2.start()





